package com.study.javaOther.permission.handle;

import com.study.javaOther.permission.accoperation.IACCOperation;
import com.study.javaOther.permission.entity.Acc;
import com.study.javaOther.permission.enums.PermissionEnum;
import com.study.javaOther.permission.enums.RuleEnum;

/**
 * @Name: ConditionDto
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2022/4/20 14:36
 * @Remark: 特殊说明
 * @Version: 1.0
 */
public class PermissionHandle extends Acc implements IAccHandle{
    @Override
    public Boolean check(PermissionEnum permission) {
        IACCOperation iaccOperation = convertOperation(getOperation());
        boolean checkResult=getRight()==null?iaccOperation.match(getLeft()):iaccOperation.match(getLeft(),getRight());
        if (checkResult) {
            String rule = permission == PermissionEnum.READ?getRead():getWrite();
            if (RuleEnum.EMPTY.equals(RuleEnum.valueOf(rule))) {
                return null;
            }else{
                return RuleEnum.ALLOW.equals(RuleEnum.valueOf(rule));
            }
        }
        return null;
    }
}
